package com.ruoyi.web.controller.emergency;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.system.domain.bo.EmgDisasterBo;
import com.ruoyi.system.domain.vo.EmgDisasterVo;
import com.ruoyi.system.service.IEmgDisasterService;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 灾情
 *
 * @author ruoyi
 * @date 2023-11-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/emg/disaster")
public class EmgDisasterController extends BaseController {

    private final IEmgDisasterService iEmgDisasterService;

    /**
     * 查询灾情列表
     */
    //@SaCheckPermission("emg:disaster:list")
    @GetMapping("/list")
    public TableDataInfo<EmgDisasterVo> list(EmgDisasterBo bo, PageQuery pageQuery) {
        return iEmgDisasterService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出灾情列表
     */
    //@SaCheckPermission("emg:disaster:export")
    @Log(title = "灾情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EmgDisasterBo bo, HttpServletResponse response) {
        List<EmgDisasterVo> list = iEmgDisasterService.queryList(bo);
        ExcelUtil.exportExcel(list, "灾情", EmgDisasterVo.class, response);
    }

    /**
     * 获取灾情详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("emg:disaster:query")
    @GetMapping("/{id}")
    public R<EmgDisasterVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iEmgDisasterService.queryById(id));
    }

    /**
     * 新增灾情
     */
    //@SaCheckPermission("emg:disaster:add")
    @Log(title = "灾情", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EmgDisasterBo bo) {
        return toAjax(iEmgDisasterService.insertByBo(bo));
    }

    /**
     * 修改灾情
     */
    //@SaCheckPermission("emg:disaster:edit")
    @Log(title = "灾情", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EmgDisasterBo bo) {
        return toAjax(iEmgDisasterService.updateByBo(bo));
    }

    /**
     * 删除灾情
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("emg:disaster:remove")
    @Log(title = "灾情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iEmgDisasterService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
